package com.example.sherlockzhong.plush_v2.Utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.View;
import android.webkit.WebView;

import com.example.sherlockzhong.plush_v2.Constants.SystemConstant;
import com.example.sherlockzhong.plush_v2.LoginActivity;
import com.example.sherlockzhong.plush_v2.MainActivity;
import com.example.sherlockzhong.plush_v2.Models.DataModel;

import java.net.CookieManager;


/**
 * Description:
 *
 * @author DosonLeung  429341159@qq.com
 * @version 1.0
 */
public class DialogUtil {

    // 定义一个显示消息的对话框
    public static void showDialogSingle(final Context ctx, String msg) {
        // 创建一个AlertDialog.Builder对象
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg).setCancelable(false);
        builder.setNegativeButton("取消", null);
        builder.create().show();
    }

    // 定义一个显示消息的对话框
    public static void showDialog(final Context ctx, String msg) {
        // 创建一个AlertDialog.Builder对象
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg).setCancelable(false);
        builder.setPositiveButton("确定", new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // 结束当前Activity
                ((Activity) ctx).finish();
            }
        });
        builder.setNegativeButton("取消", null);
        builder.create().show();
    }

    //注销
    // 定义含有确定和取消的对话框
    public static void exitDialog(final MainActivity app, final Context ctx, String msg) {
        // 创建一个AlertDialog.Builder对象
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx)
                .setMessage(msg).setCancelable(false);
        builder.setPositiveButton("确定", new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                app.controller.stopNotification();
                DataModel.removeUserData(app);
                SystemConstant.show = new WebView(ctx);
                SystemConstant.show.clearHistory();
                SystemConstant.show.clearCache(true);
                SystemConstant.show.clearFormData();
                SystemConstant.poster = false;
                Intent intent = new Intent(app, LoginActivity.class);
                app.startActivity(intent);
                app.finish();
            }
        });
        builder.setNegativeButton("取消", null);
        builder.create().show();
    }

    // 定义一个显示指定组件的对话框
    public static void showDialog(Activity app, Context ctx, View view) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setView(view).setCancelable(false)
                .setPositiveButton("确定", new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        builder.create().show();
    }

}

